
// index.js
// 获取应用实例
const App = getApp();
const HTTP = require('../../utils/util');
const common = require('../../libs/common');
Page({
    data: {
        loading:false,
        swiperList: [],
        shopCateList: [],
        shopList: [],
        city: '',
        shopPage: 1,
        shopPageNumber: 10,
        vip_img: '',
        cate_id: '',
        goBack: 0,
        vertical: false,
        autoplay: true,
        interval: 2000,
        duration: 500,
    },
    onLoad(options) {
        this.setData({
            cate_id: options.id
        });
    },
    //获取这个页面的总数据
    getClassTwo(e) {
        this.setData({
            loading:true,
        })
        HTTP.getData('/api/shop/cateList', {
            cate_id: e,
            limit: this.data.shopPageNumber,
            page: this.data.shopPage
        }, res => {
            this.isActive(res.data.cate);
            this.setData({
                goBack: 0,
                swiperList: res.data.slide,
                cateList: res.data.cate,
                loading:false
            });
            common.handlePageChange(this.data.shopPage, res.data.shop.data, this.data.shopList, (e) => { this.setData({ shopList: e }) }, '商铺');
        });
    },
    //上拉加载
    onReachBottom(e) {
        this.setData({
            shopPage: this.data.shopPage + 1
        });
        this.getClassTwo(this.data.cate_id);
    },
    //取出classone中存的catelist
    getCateList() {
        let arr = App.globalData['cate2'].shopCateList;
        App.globalData['cate2'].shopCateList2.map(item => {
            arr.push(item);
        });
        this.isActive(arr);
        this.setData({
            cateList: arr
        })

    },
    // 判断哪个cate ACtive
    isActive(res) {
        res.map(item => {
            if (item.id === Number(this.data.cate_id)) {
                item['active'] = true;
            }
        });
    },
    //点击二级分类切换商家
    changeShop(e) {
        this.setData({
            cate_id: e.target.dataset.id,
            shopPage: 1,
            shopPageNumber: 10,
        });
        this.getClassTwo(this.data.cate_id);
    },
    onShow() {
        this.setData({
            swiperList:wx.getStorageSync('swiperList')
        }),
        this.getClassTwo(this.data.cate_id);
    },
    onSearch(e) {
        console.log(e.detail)
    }

})

